<template>
	<view>
		<image src="../../static/login/top.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.jpg" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">有我在您可放心畅饮</text>
		</view>
		<button class="btn" @tap="subscribeMessage()">乘客登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">小程序仅限于飞驰专车代驾使用,登录前请先进行微信注册,注册前请消息阅读注册需求和使用流程</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			code: null
		};
	},
	methods: {
		subscribeMessage(){
			var _this = this;
			wx.login({
				// 成功返回
			  success (res) {
				  console.log(res.code)
				  //拿到微信授权码
				  let code = res.code;
			    if (res.code) {
					var parm = {
						code :res.code,
						type : _this.Consts.TYPE_VALUE
					}
					//发起微信注册请求Vue.prototype.post = function(url,  data, fun) 封装好的 fun返回数据
					_this.post("/uaa/manager/login/wechatLogin",parm,function(res){
						console.log(res)
						let {success,code,message,result} = res.data;
						uni.setStorageSync("username",res.data.data.username);
						uni.setStorageSync("nick_name",res.data.data.nick_name);
						uni.setStorageSync("token",res.data.data.token);
						uni.setStorageSync("phone",res.data.data.phone);
						uni.setStorageSync("avatar",res.data.data.avatar);
						uni.switchTab({
							url: '../workbench/workbench'
						});
					});
			    }else{
					console.log("登录失败！"+res.errMsg)
				}
			  }
			})
		},
		toRegisterPage(){
			//在起始页面跳转到test.vue页面并传递参数
			uni.navigateTo({
				url: '../register/register'
			});
		}
		
	},
	onLoad: function() {}
};
</script>

<style lang="less">
@import url('login.less');
</style>
